﻿using System;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;
using System.Data;
using System.Drawing.Design;
using System.ComponentModel;
using Microsoft.VisualBasic;

namespace PropertyGridEx
{

    public class TypeConverter_Int32 : Int32Converter
    {
        private bool bMsgboxIsVisible = false;
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            try
            {
                return base.ConvertFrom(context, culture, value);
            }
            catch (Exception ex)
            {
                if (!bMsgboxIsVisible)
                {
                    bMsgboxIsVisible = true;
                    Interaction.MsgBox("输入错误,输入值'" + value + "'必须为整形数字,请重新输入", MsgBoxStyle.Exclamation, "错误信息");
                }
                bMsgboxIsVisible = false;
                return context.PropertyDescriptor.GetValue(this);
            }
        }
    }


    public class TypeConverter_Double : DoubleConverter
    {
        private bool bMsgboxIsVisible = false;
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            try
            {
                return base.ConvertFrom(context, culture, value);
            }
            catch (Exception ex)
            {
                if (!bMsgboxIsVisible)
                {
                    bMsgboxIsVisible = true;
                    Interaction.MsgBox("输入错误,输入值'" + value + "'必须为数字,请重新输入", MsgBoxStyle.Exclamation, "错误信息");
                }
                bMsgboxIsVisible = false;
                return context.PropertyDescriptor.GetValue(this);
            }
        }
    }


    public class TypeConverter_DateTime : DateTimeConverter
    {
        private bool bMsgboxIsVisible = false;
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            try
            {
                return base.ConvertFrom(context, culture, value);
            }
            catch (Exception ex)
            {
                if (!bMsgboxIsVisible)
                {
                    bMsgboxIsVisible = true;
                    Interaction.MsgBox("输入错误,输入值'" + value + "'不是有效的日期类型,请重新输入", MsgBoxStyle.Exclamation, "错误信息");
                }
                bMsgboxIsVisible = false;
                return context.PropertyDescriptor.GetValue(this);
            }
        }
    }

}
